import request from '../axios'

export const getCaptcha = () =>
  request({
    url: '/api/blade-auth/captcha',
    method: 'get',
  })

export const getTenList = (param) =>
  request({
    url: '/api/blade-user/user-tenant-list',
    method: 'get',
    params: {
      ...param,
    },
  })

export const changeTenant = (param) => {
  return request({
    url: '/api/blade-auth/cutTenant',
    method: 'post',
    data: param,
  })
}

export const loginByUsername = (param) =>
  request({
    url: '/api/blade-auth/token',
    method: 'post',
    headers: {
      'Captcha-Key': param.key,
      'Captcha-Code': param.code,
    },
    params: {
      ...param,
    },
  })

export const register = (param) =>
  request({
    url: '/api/blade-user/addAppUser',
    method: 'post',
    params: {
      ...param,
    },
  })
export const upPassWord = (param) =>
  request({
    url: '/api/blade-user/update-password',
    method: 'post',
    params: {
      ...param,
    },
  })
export const findTenList = (tenantName) =>
  request({
    url: '/api/blade-system/tenant/findTenList',
    method: 'get',
    params: {
      tenantName,
    },
  })

export const getMsgCode = (phoneNo) =>
  request({
    url: '/api/blade-bce/bceSms/sendMsg',
    method: 'get',
    params: {
      phoneNo,
    },
  })

export const loginByPhone = (params) =>
  request({
    url: '/api/blade-auth/token',
    method: 'post',
    params: {
      grantType: 'phone',
      ...params,
    },
  })
